﻿using System.Windows;
using System.Windows.Controls;

namespace PLCSharp.CoreModel.UserControls
{
    /// <summary>
    /// PasswordBoxNew.xaml 的交互逻辑
    /// </summary>
    public partial class PasswordBoxNew : UserControl
    {
        public PasswordBoxNew()
        {
            InitializeComponent();
        }

        private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            Text = ((PasswordBox)sender).Password;
        }



        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(PasswordBoxNew), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, TextSourceChangedCallback));

        private static void TextSourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var obj = ((PasswordBoxNew)d);

            if (obj.Text == "")
                obj.passwordBox.Password = obj.Text;

        }
    }
}
